package com.mb.app.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.mb.app.domain.TbAppInfo;
import com.mb.app.dao.TbAppInfoMapper;
import com.mb.app.service.ITbAppInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 应用配置信息  服务实现类
 * </p>
 *
 * @author liliping
 * @since 2019-03-21
 */
@Service
@Slf4j
public class TbAppInfoServiceImpl extends ServiceImpl<TbAppInfoMapper, TbAppInfo> implements ITbAppInfoService {


    @Override
    public List<TbAppInfo> queryList(Map<String, Object> map) {
        List<TbAppInfo> list = this.baseMapper.lst(map);
        return list;
    }

    @Override
    public int count(Map<String, Object> map) {
        return this.baseMapper.count(map);
    }

    @Override
    public int save(TbAppInfo tbAppInfo) {
        tbAppInfo.setCreateTime(new Date());
        return this.baseMapper.insert(tbAppInfo);
    }

    @Override
    public int update(TbAppInfo tbAppInfo) {
        try {
            TbAppInfo tbAppInfo1 = new TbAppInfo();
            tbAppInfo1.setAppId(tbAppInfo.getAppId());
            tbAppInfo1.setDataStatus(1);
            TbAppInfo tbAppInfoDO = this.baseMapper.selectOne(tbAppInfo1);
            if(tbAppInfoDO != null){
                tbAppInfo.setUpdateTime(new Date());
                this.baseMapper.updateById(tbAppInfo);
            }
        } catch (Exception e) {
            log.error("update Exception",e);
        }
        return 0;
    }

    

    @Override
    public int remove(Long appId) {
//        return this.baseMapper.deleteById(appId);
        TbAppInfo tbAppInfo = new TbAppInfo();
        tbAppInfo.setAppId(appId);
        tbAppInfo.setDataStatus(0);
        return this.baseMapper.updateById(tbAppInfo);
    }

    @Override
    public TbAppInfo getDtl(Long appId) {
        return this.baseMapper.selectById(appId);
    }

    @Override
    public boolean appNameCodeExit(Map<String, Object> params) {
        boolean exit;
        exit = this.baseMapper.selectByAppInfo(params).size() > 0;
        return exit;
    }
    @Override
    public List<TbAppInfo> getAppInfoList(Map<String, Object> map) {
        List<TbAppInfo> tbAppInfos = this.baseMapper.selectByAppInfo(map);
        return tbAppInfos;
    }

}
